{% extends "EMNewsBundle::layoutAdmin.html.twig" %}
{% block title 'News - Edit Category' %}
{% block scripts%}    
<script type="text/javascript" class="source below">
// Note method 2) and 3) use `one`, this is because if `refresh` is called those events are triggered
$(function () {
	$("#demo2")
		.jstree({ "plugins" : ["themes","html_data","ui"] })
		// 1) the loaded event fires as soon as data is parsed and inserted
		.bind("loaded.jstree", function (event, data) { })
		// 2) but if you are using the cookie plugin or the core `initially_open` option:
		.one("reopen.jstree", function (event, data) { })
		// 3) but if you are using the cookie plugin or the UI `initially_select` option:
		.one("reselect.jstree", function (event, data) { })
                .one("select_node.jstree", function (event, data) {
                console.log(data);
                var url=data.rslt.obj.attr("id"); 
               // var link={{ path('cat_example', {'id': 'catid'}) }};
               // link = link.replace("catid", cat);
               /// console.log(link)
               // console.log(cat);
                $.ajax({type: 'POST', url:url, script:true, cache:false,
                success: function(data) {
			if (data === "false"){

			}else{
		      
                        $('#formcontent').html(data);
                        
			}
                } });
        });
});

</script>
{% endblock%}

{% block content %}

    <!--	<div class="title"><h5>Edit Category </h5></div>-->
        
<div class="left" id="formcontent"> 

</div>
<div class="right">
<div class="widget">
    <div class="head" id="opened"><h5>Category directory</h5></div>
<div id="demo2" class="demo" >

                         
                            {% for key, category in categories%}
                                {% if category.level==0 %}
                                    <ul><li id="{{ path('cat_example', {'id': category.id}) }}" class="jstree-open">
                                      <a href="#" id="cat" >{{ category.name}}</a>
                                      {% for   cat in categories%}
                                            {% if cat.categoryParent!=null%}
                                                  {% if category.id==cat.categoryParent.id%}
                                                     <ul><li id="{{ path('cat_example', {'id': cat.id}) }}" class="jstree-open">
                                                        <a href="#">&nbsp; {{  cat.name}}</a>
                                                        {% for   subcat in categories%}
                                                             {% if subcat.categoryParent!=null%}
                                                                    {% if cat.id==subcat.categoryParent.id%}
                                                                     <ul><li id="{{ path('cat_example', {'id': subcat.id}) }}" class="jstree-open">
                                                                      <a href="#">&nbsp;&nbsp; {{  subcat.name}}</a>
                                                                         {% for   subscat in categories%}
                                                                                {% if subscat.categoryParent!=null%}
                                                                                        {% if subcat.id==subscat.categoryParent.id%}
                                                                                          <ul><li id="{{ path('cat_example', {'id': subscat.id}) }}" class="jstree-open">
                                                                                         <a href="#">&nbsp;&nbsp;&nbsp;&nbsp; {{  subscat.name}}</a >
                                                                                         </li> </ul>
                                                                                        {%endif%}
                                                                                {%endif%}
                                                                         {% endfor%}
                                                                    </li> </ul>
                                                                    {%endif%}
                                                              {%endif%}
                                                        {% endfor%}
                                                  </li> </ul>
                                                  {% endif%}
                                            {% endif%}
                                      {% endfor%}
                                      </li></ul>
                                {% endif %}
                            {% endfor %}
    </div>
    </div>
</div>
    <script type="text/javascript" >

 /*       $("#cat").click(function (){ 
	
	$.ajax({type: 'POST', url:'{{ path('cat_example', {'id': '1'}) }}', script:true, cache:false,
        success: function(data) {
			if (data === "false"){

			}else{
		      	console.log(data);
                        
			}
	 } });
	   
});*/
</script>    
{% endblock %}			
              